package 函数式接口;

import org.junit.Test;

import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * 函数式接口学习
 *
 * @Author: SunAo
 * @Date: 2021/2/4 17:29
 */
public class 函数式接口学习 {

    /**
     * 消费传入参数
     */
    @Test
    public void Consumer简单试用(){
        Consumer<String> consumer = s-> System.out.println(s);
        consumer.accept("Hello world");
    }

    @Test
    public void BiConsumer简单试用(){
        BiConsumer<String,Integer> consumer = (s,i)-> System.out.println(s+i);
        consumer.accept("Number:",1);
    }

    /**
     * 返回一个值
     */
    @Test
    public void Supplier简单试用(){
        Supplier<String> supplier = ()->"Hello World";
        String r = supplier.get();
        System.out.println(r);
    }

    /**
     * 判断传入参数，返回布尔值
     */
    @Test
    public void Predicate简单试用(){
        Predicate<String> predicate = str->str.equals("Hello");
        boolean r = predicate.test("Hello");
        System.out.println(r);
    }

    @Test
    public void BiPredicate简单试用(){
        BiPredicate<String,Integer> biPredicate = (s,i)->i.toString().equals(s);
        boolean r = biPredicate.test("1", 1);
        System.out.println(r);
    }


}
